<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style media="screen">
        *{
            margin: 0;
            padding: 0;
        }
        #box{
            width:800px;
            height:600px;
            position: relative;
            margin: 100px auto;
            background:#000000;
            border:2px solid red;
            overflow: hidden;
        }
        .ball{
            width: 10px;
            height: 10px;
            border-radius: 50%;
            position: absolute;
            bottom: 0;
        }
    </style>
</head>
<body>
    <div id="box"></div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
        function FireWork(){
            //获取元素
            this.container = document.querySelector('#box');
            this.bindEvent();
        }
        //绑定事件
        FireWork.prototype.bindEvent = function(e){
            var self = this;
            //绑定点击事件
            self.container.onclick = function(){
                var e = e || window.event;
                var fireWork = self.createFireWork();
                fireWork.style.left = e.offsetX + 'px';
                //运动
                $(fireWork).animate({
                    top: e.offsetX
                },800,function(){
                    fireWork.remove();
                })
            }
        }
        FireWork.prototype.createFireWork = function(){
            //创建小圆球，即div
            //将div放入页面中
            var div = document.createElement('div');
            div.className = 'ball';
            div.style.backgroundColor = '#' + Math.round(parseInt('ffffff',16)*Math.random()).toString(16).padStart(6,'0');
            this.container.appendChild(div);
            return div;
        }
        var fw = new FireWork();
    </script>
</body>
</html>